﻿using EscapeZone.Components;
using Microsoft.Xna.Framework;
using XnaPlus.Common.Extensions;
using XnaPlus.Common.Geometry;
using XnaPlus.Common.Interfaces;
using XnaPlus.StateManagement.Screens;

namespace EscapeZone.Weapons
{
    public class Projectile : DrawableEscapeGameComponent, IPositionable
    {
        private readonly Vector2 m_startingPosition;

        public Vector2 Position { get; set; }

        public Circle Bounds { get{ return new Circle(Position, Radius);} }

        public float Radius { get; set; }

        public Vector2 Velocity { get; set; }

        public float Range { get; set; }

        public Projectile(EscapeGame game, Screen screen, Vector2 position) : base(game, screen)
        {
            Radius = 4;
            Position = position;
            m_startingPosition = position;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if ((Position - m_startingPosition).Length() >= Range)
            {
                Enabled = false;
                Visible = false;
            }
            else
            {
                Position += Velocity;
            }

        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            Game.Drawer.DrawCircle(Bounds, Color.Black);
        }
    }
}